#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;

int longestLine(int n, int m, vector<pair<int, int>>& pieces) {
    if (m == 0) return 0;

    unordered_map<int, vector<int>> row_map;
    unordered_map<int, vector<int>> col_map;
    for (const auto& piece : pieces) {
        int x = piece.first;
        int y = piece.second;
        row_map[x].push_back(y);
        col_map[y].push_back(x);
    }

    int max_length = 0;
    for (const auto& row : row_map) {
        const vector<int>& positions = row.second;
        if (positions.size() > 1) {
            int min_pos = *min_element(positions.begin(), positions.end());
            int max_pos = *max_element(positions.begin(), positions.end());
            max_length = max(max_length, max_pos - min_pos);
        }
    }
    for (const auto& col : col_map) {
        const vector<int>& positions = col.second;
        if (positions.size() > 1) {
            int min_pos = *min_element(positions.begin(), positions.end());
            int max_pos = *max_element(positions.begin(), positions.end());
            max_length = max(max_length, max_pos - min_pos);
        }
    }

    return max_length;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> pieces(m);

    for (int i = 0; i < m; ++i) {
        cin >> pieces[i].first >> pieces[i].second;
    }

    int result = longestLine(n, m, pieces);
   cout << result << endl;

    return 0;
}
